package com.android.volley.components.volley;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.Map;

/**
 * 网络请求方法实现
 * Created by Kim on 16/6/6.
 */
public class GsonRequest extends StringRequest {
    private final Map<String, String> headers;
    private final Map<String, String> params;
//    private final Response.Listener<String> listener;
    /**
     * 网络请求方法
     *
     * @param method        请求类型
     * @param url           请求地址
     * @param headers       头文件参数
     * @param params        post参数
     * @param listener      监听
     * @param errorListener 错误监听
     */
    public GsonRequest(int method, String url, Map<String, String> headers, Map<String, String> params, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
        this.headers = headers;
//        this.listener = listener;
        this.params = params;
    }


    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        return headers != null ? headers : super.getHeaders();
    }

    @Override
    public Map<String, String> getParams() throws AuthFailureError {
        return params != null ? params : super.getHeaders();
    }



//    @Override
//    protected void deliverResponse(String response) {
//        listener.onResponse(response);
//    }




//    @Override
//    protected Response<String> parseNetworkResponse(NetworkResponse response) {
//        try {
//            String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
////            Utils.logError("GsonRequest", jsonString);
//            return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response));
//        } catch (UnsupportedEncodingException e) {
//            return Response.error(new ParseError(e));
//        }
//    }

//    @Override
//    protected Response<String> parseNetworkResponse(NetworkResponse response) {
//        String parsed;
//        try {
//            parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
//        } catch (UnsupportedEncodingException var4) {
//            parsed = new String(response.data);
//        }
//
//        return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
//    }


}
